C: do {...} while(0)?
        Posted  
        
            by igul222
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by igul222
        
        
        
        Published on 2010-04-22T00:58:13Z
        Indexed on 
            2010/04/22
            1:03 UTC
        
        
        Read the original article
        Hit count: 355
        
I'm working on some C code filled with macros like this:
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
Can anyone explain what this macro does, and why do {} while(0) is needed? Wouldn't that just execute the code once?
© Stack Overflow or respective owner